package com.petadoption.serverclient.controller;

import com.petadoption.serverclient.entity.Examineneck;
import com.petadoption.serverclient.entity.Neck;
import com.petadoption.serverclient.entity.User;
import com.petadoption.serverclient.service.IExamineneckService;
import com.petadoption.serverclient.service.INeckService;
import com.petadoption.serverclient.service.IUserService;
import com.petadoption.serverclient.utils.Result;
import com.petadoption.serverclient.vo.ExamineNeckVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 汪仕杰
 * @since 2023-08-28
 */
@RestController
@RequestMapping("/examineneck")
public class ExamineneckController {
    @Resource
    private Result result;
    @Resource
    private INeckService neckService;
    @Resource
    private IExamineneckService examineneckService;
    @Resource
    private IUserService userService;

    @PostMapping("/adoptinfo")
    public Result addExamineneck(@RequestBody ExamineNeckVO examineNeckVO) {
        User user = userService.findNameByPhone(examineNeckVO.getNeckPhone());
        System.out.println(user);
        Neck neck = new Neck();
        neck.setNeckName(user.getUserName());
        neck.setNeckSex(examineNeckVO.getNeckSex());
        neck.setNeckAddress(examineNeckVO.getNeckAddress());
        neck.setNeckPhone(examineNeckVO.getNeckPhone());
        neck.setNeckMessage(examineNeckVO.getNeckMessage());
        neck.setAdoptExperience(examineNeckVO.getAdoptExperience());
        neck.setAdoptMarital(examineNeckVO.getAdoptMarital());
        neck.setAdoptHouse(examineNeckVO.getAdoptHouse());
        neck.setAdoptJob(examineNeckVO.getAdoptJob());
        neck.setAdoptAge(examineNeckVO.getAdoptAge());
        neck.setAdoptHavepet(examineNeckVO.getAdoptHavepet());
        neck.setAdoptIncome(examineNeckVO.getAdoptIncome());
        neck.setNeckPet(examineNeckVO.getNeckPet());
        System.out.println("领养的宠物：" + examineNeckVO.getNeckPet());
        int i = neckService.addNeck(neck);
        if (i < 0) return result.fail("领养失败");
        Examineneck examineneck = new Examineneck();
        examineneck.setExamineneckName(neck.getNeckId());
        examineneck.setExamineneckTime(LocalDateTime.now());
        examineneck.setExamineneckPet(examineNeckVO.getNeckPet());
        int i1 = examineneckService.addExamineneck(examineneck);
        if (i1 < 0) return result.fail("领养失败");
        return result.success("领养审核中...");
    }
}
